import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import os

# 打开浏览器
driver = webdriver.Chrome()
# 获取本地路径并请求网址
url = 'file:///' + os.path.abspath('html') + '/注册实例.html'
driver.get(url)
# 创建select对象，参数是要操作的select标签
s1 = driver.find_element(By.ID, 'select')
select = Select(s1)

# 选择option
time.sleep(2)
# 通过value值选取option
select.select_by_value('cq')

time.sleep(2)
# 通过索引选取option, 索引从0开始
select.select_by_index(1)

time.sleep(2)
# 通过文本选取option
select.select_by_visible_text('广州')

# 退出浏览器
time.sleep(5)
driver.quit()

